import java.util.LinkedList;

/**
 * The second type of container. It can load different types of goods until it
 * is full. It can load different types of goods in one side, so that unloading
 * sequence is opposite to the loading sequence.
 * 
 * @author Xi
 * 
 */
public class Container2 extends Container {

	public Container2(int capacity) {
		super(capacity);
	}

	@Override
	public void load(Goods goods) {
		// check if the container is able to load the new goods
		if ((weight + goods.getWeight()) <= capacity) {
			goodsList.add(goods); // insert new goods into the container
			weight += goods.getWeight(); // change the container weight
			System.out.println("The goods is loaded, goods weight: "
					+ goods.getWeight() + " , goods type: " + goods.getType()
					+ " , goods value: " + goods.getValue());
		} else {
			System.out
					.println("The goods can not be loaded, because the container is already full!");
		}
	}

	@Override
	public void unload() {
		if (!goodsList.isEmpty()) {
			// remove the goods from the container
			Goods removedGoods = goodsList.remove(goodsList.size() - 1);
			weight -= removedGoods.getWeight(); // change the container weight
			System.out.println("The goods is removed, goods weight: "
					+ removedGoods.getWeight() + " , goods type: "
					+ removedGoods.getType() + " , goods value: "
					+ removedGoods.getValue());
		}
	}

}
